package org.wzys.Controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.wzys.Pojo.LoginInfo;
import org.wzys.Pojo.Result;
import org.wzys.Pojo.User;
import org.wzys.Service.UserService;

@Slf4j
@RestController
public class UtilsController {

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public Result register(@RequestBody User user) {
        log.info("注册用户");
        userService.register(user);
        return Result.success();
    }


    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        log.info("员工来登录啦 , {}", user);
        LoginInfo loginInfo = userService.login(user);
        if(loginInfo != null){
            return Result.success(loginInfo);
        }
        return Result.error("用户名或密码错误~");

    }
}
